/*
 * @Author: wuqingchun
 * @Date: 2024-04-20 14:23:26
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-05-07 10:08:38
 */
#include <iostream>
#include <array>
#include <vector>

#include "my_array.h"
#include "template_func.h"
#include "template_class.h"

void test_array()
{
    std::array<int, 10> arrData = {1, 2};

    try
    {
        std::cout << arrData.at(10) << std::endl;
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << '\n';
    }
    
    for (auto& item : arrData)
    {
        std::cout << item << std::endl;
    }

    std::array<int, 10>::iterator it = arrData.begin();
    while (it != arrData.end())
    {
        std::cout << *it << std::endl;
        it++;
    }
}

void test_myarray()
{
    MyArray<int, 10> arrData = {1, 2};

    std::cout << arrData.at(0) << std::endl;

    try
    {
        std::cout << arrData.at(10) << std::endl;
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << '\n';
    }

    MyArray<int, 10>::iterator it = arrData.begin();
    while (it != arrData.end())
    {
        std::cout << *it << std::endl;
        it++;
    }
}

int main(int argc, char** argv)
{
    //test_array();

    test_myarray();

    std::cout << add(1, 2) << std::endl;
    std::cout << add(1.0, 2.0) << std::endl;

    int iValue = 10;
    double dfValue = 10.23;
    std::string strValue = "Hello World!";

    my_print(iValue);
    my_print(iValue, dfValue);
    my_print(iValue, dfValue, strValue);
    my_print(10, "aaa");
    my_print(std::move(10), std::move("bbb"));

    // 使用模板参数默认值进行模板类实例化
    WorkerThread<> objThread;
    objThread.Start<3>();
    objThread.Start<&WorkerThread<>::StartProducer>();

    // 指定模板参数进行类模板实例化，覆盖模板参数默认值
    WorkerThread<WorkMode::WMODE_CONSUMER_PRODUCER> objThread2;
    // 指定模板参数默认值进行函数模板实例化
    objThread2.Start();
    objThread.Start<&WorkerThread<>::StartConsumer>();

    std::cout << Less(10, 20, [](int a, int b)->int{ return a - b;}) << std::endl;
    std::cout << Less(10, 20, std::bind(CmpInt, std::placeholders::_1, std::placeholders::_2)) << std::endl;

    int iValue1 = 10;
    int iValue2 = 20;
    std::cout << Less(iValue1, iValue2, std::bind(CmpInt, std::placeholders::_1, std::placeholders::_2)) << std::endl;
    std::cout << Less(std::move(1), std::move(2), std::bind(CmpInt, std::placeholders::_1, std::placeholders::_2)) << std::endl;
    std::cout << Less(&iValue1, &iValue2, std::bind(CmpIntPtr, std::placeholders::_1, std::placeholders::_2)) << std::endl;

    Sub(1, 2);
    Sub(1.0, 2.0);

    MyAdder<int, int> objAdder1;
    MyAdder<int, double> objAdder2;
    MyAdder<double, double> objAdder3;

    return 0;
}